package com.lhkj.ct.meta.modules.patient.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lhkj.ct.meta.modules.patient.model.entity.TblPatCardRelation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户绑定就诊卡 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2023-12-15
 */
public interface PatCardRelationMapper extends BaseMapper<TblPatCardRelation> {

    @Select("select " +
            "t.id, t.is_default, t.identifier, t.pat_card_no, " +
            "if(t.pat_id = #{currentUserId}, 1, 0) as `current` ," +
            "t1.pat_name, fun_convert_dictionary(t1.pat_sex, '${@com.lhkj.ct.base.constants.DictConstants@GENDER}') as pat_sex " +
            "from tbl_pat_card_relation t " +
            "inner join tbl_patient t1 on t1.id = t.pat_id " +
            "where t.identifier = #{identifier,jdbcType=VARCHAR}")
    List<TblPatCardRelation> selectByUser(@Param("identifier") String identifier, @Param("currentUserId") String currentUserId);

}
